<template>
  <div class="app-container">
    <div>
      <el-row class="admin-top-g">
        <GButton
          :is-add-show="false"
          :is-edit-show="false"
          :is-del-show="!!(limits.length >=1 && limits.filter(it => it.FName === '删除').length)"
          :lists="options"
          :is-settings-show = "lookSetShow"
          @onAdd="addUser"
          @onEdit="editUser"
          @onDelete="delUser"
          @selectSettings="selectSettings"
      /></el-row>
      <br>

      <el-row class="common-row">
        <template v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length">
          <el-input v-model="keyword" clearable style="width: 160px;" placeholder="请输入关键字" @keyup.native.enter="searchUser" @change="searchUser"/>
          <el-select v-model="fstatus" clearable filterable style="width: 150px;" placeholder="请选择审核状态" @change="searchUser">
            <el-option
              v-for="item in statusList"
              :key="item.fstatus"
              :label="item.fname"
              :value="item.fstatus"/>
          </el-select>
          <el-select v-model="fisranyouhz" clearable filterable style="width: 150px;" placeholder="请选择" @change="searchUser">
            <el-option
              v-for="item in fisranyouhzList"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <el-button type="primary" icon="el-icon-search" @click="searchUser">搜索</el-button>
        </template>

        <!-- <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '导入').length" type="primary" icon="el-icon-refresh" @click="exportTableData">导入 </el-button> -->

        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '导出').length" type="primary" icon="el-icon-my-export" @click="downData">导出</el-button>
        <!-- <el-button type="primary" icon="el-icon-my-updown" @click="handleDownload">下载{{ fmofanName }}模板</el-button> -->

        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '审核').length" type="primary" icon="el-icon-circle-check" @click="check('1')">审核</el-button>
        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '反审核').length" type="primary" icon="el-icon-close" @click="check('0')">反审</el-button>

        <el-button type="primary" icon="el-icon-refresh" @click="refresh">刷新 </el-button>

      </el-row>
    </div>
    <br>
    <el-table
      v-loading="listLoading"
      v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
      :data="tableData"
      :summary-method="getSummaries"
      :header-cell-style="tableHeaderStyle"
      :height="tableHeight"
      show-summary
      class="tableCss"
      element-loading-text="正在加载"
      border
      highlight-current-row
      @row-dblclick="tableClick"
      @selection-change="handleSelectionChange"
      @current-change="salaryCurrentChange">
      <el-table-column
        type="selection"
        width="55"/>
      <template v-for="item in formThead">
        <el-table-column v-if="item.frpttypeflag ==0" :key="item.fid" :label="item.frepcap" :prop="item.frepfld" :width="item.frepwid" align="center" show-overflow-tooltip>

          <template slot-scope="scope">
            <template v-if="item.frephide<=0">
              <template v-if="item.frepfld === 'fstatus'">
                <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                <el-tag v-else size="mini" type="danger">未审</el-tag>
              </template>
              <template v-else size="mini">
                {{ scope.row[item.frepfld] }}
              </template>
            </template>
          </template>

        </el-table-column>
      </template>
    </el-table>

    <el-pagination
      v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
      :total="total"
      :page-sizes="pagesizes"
      :page-size="pagesize"
      :current-page.sync="currentPage"
      class="jy-pagination"
      style="text-align: center; margin-top: 20px;"
      background
      layout="sizes, prev, pager, next, total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"/>

    <el-dialog v-el-drag-dialog :close-on-click-modal="false" :visible.sync="jxModel" :append-to-body="true" class="drag-set-modal" top="10vh" width="80%" title="汇总">
      <div class="detail">
        <div class="btn_box"><el-button size="mini" style="float: right; " type="primary" icon="el-icon-download" @click="exportSCBJD">导出 </el-button></div>

        <table id="st" cellpadding="0" cellspacing="0">
          <thead>
            <tr>
              <th colspan="7">首台机台架试车中燃料等消耗量(增压器匹配)</th>
            </tr>
            <tr class="title">
              <th>序号</th>
              <th>项目</th>
              <th>消耗量（kg）</th>
              <th>消耗量（L）</th>
              <th>机型配置</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>1</td>
              <td>燃油</td>
              <td>{{ detailRes.fstranyoucgj }}</td>
              <td>{{ (detailRes.fstranyoucgj/0.835).toFixed(2) }}</td>
              <td>常规机</td>
            </tr>
            <tr>
              <td>2</td>
              <td>燃油</td>
              <td>{{ detailRes.fstranyoucgjscr }}</td>
              <td>{{ (detailRes.fstranyoucgjscr/0.835).toFixed(2) }}</td>
              <td>常规机带HPSCR/LPSCR/EGRBP/iSCR</td>
            </tr>
            <tr>
              <td>3</td>
              <td>燃油</td>
              <td>{{ detailRes.fstranyoucgjegr }}</td>
              <td>{{ (detailRes.fstranyoucgjegr/0.835).toFixed(2) }}</td>
              <td>常规机带EcoEGR</td>
            </tr>
            <tr>
              <td>4</td>
              <td>燃油</td>
              <td>{{ detailRes.fstranyousyldf }}</td>
              <td>{{ (detailRes.fstranyousyldf/0.835).toFixed(2) }}</td>
              <td>双燃料DF机,DF机ICER燃气版,DF带SCR用此乘以1.5</td>
            </tr>
            <tr>
              <td>5</td>
              <td>燃油</td>
              <td>{{ detailRes.fstranyousylicer }}</td>
              <td>{{ (detailRes.fstranyousylicer/0.835).toFixed(2) }}</td>
              <td>DF机带iCER燃油版</td>
            </tr>
            <!-- 燃气 -->
            <tr>
              <td>6</td>
              <td>燃气</td>
              <td>{{ detailRes.fstranqisyldf }}</td>
              <td>{{ (detailRes.fstranqisyldf/0.792).toFixed(2) }}</td>
              <td>双燃料DF机,DF带SCR</td>
            </tr>
            <tr>
              <td>7</td>
              <td>燃气</td>
              <td>{{ detailRes.fstranqisylicer }}</td>
              <td>{{ (detailRes.fstranqisylicer/0.792).toFixed(2) }}</td>
              <td>DF机带iCER燃油版或燃气版</td>
            </tr>
            <!-- 汽缸油 -->
            <tr>
              <td>8</td>
              <td>汽缸油</td>
              <td>{{ detailRes.fstqigangyoucgj }}</td>
              <td>{{ (detailRes.fstqigangyoucgj/0.945).toFixed(2) }}</td>
              <td>常规机</td>
            </tr>
            <tr>
              <td>9</td>
              <td>汽缸油</td>
              <td>{{ detailRes.fstqigangyoucgjscr }}</td>
              <td>{{ (detailRes.fstqigangyoucgjscr/0.945).toFixed(2) }}</td>
              <td>常规机带HPSCR/LPSCR/EGRBP/iSCR</td>
            </tr>
            <tr>
              <td>10</td>
              <td>汽缸油</td>
              <td>{{ detailRes.fstqigangyoucgjegr }}</td>
              <td>{{ (detailRes.fstqigangyoucgjegr/0.945).toFixed(2) }}</td>
              <td>常规机带EcoEGR</td>
            </tr>
            <tr>
              <td>11</td>
              <td>汽缸油</td>
              <td>{{ detailRes.fstqigangyousyldf }}</td>
              <td>{{ (detailRes.fstqigangyousyldf/0.945).toFixed(2) }}</td>
              <td>双燃料DF机</td>
            </tr>
            <tr>
              <td>12</td>
              <td>汽缸油</td>
              <td>{{ detailRes.fstqigangyousylicerry }}</td>
              <td>{{ (detailRes.fstqigangyousylicerry/0.945).toFixed(2) }}</td>
              <td>DF机带iCER燃油版</td>
            </tr>
            <tr>
              <td>13</td>
              <td>汽缸油</td>
              <td>{{ detailRes.fstqigangyousylicerrq }}</td>
              <td>{{ (detailRes.fstqigangyousylicerrq/0.945).toFixed(2) }}</td>
              <td>DF机带iCER燃气版</td>
            </tr>
            <!-- 尿素 -->
            <tr>
              <td>14</td>
              <td>尿素</td>
              <td>-</td>
              <td>{{ detailRes.fstniaosucgjscr }}</td>
              <td>常规机带HPSCR/LPSCR/iSCR</td>
            </tr>
            <!-- 氢氧化钠 -->
            <tr>
              <td>15</td>
              <td>氢氧化钠</td>
              <td>-</td>
              <td>{{ detailRes.fstnaohcgjegrbp }}</td>
              <td>常规机带EGRBP</td>
            </tr>
            <tr>
              <td>16</td>
              <td>氢氧化钠</td>
              <td>-</td>
              <td>{{ detailRes.fstnaohcgjecoegr }}</td>
              <td>常规机带EcoEGR</td>
            </tr>
            <tr>
              <td>17</td>
              <td>氢氧化钠</td>
              <td>-</td>
              <td>{{ detailRes.fstnaohsrlicerry }}</td>
              <td>DF机带iCER燃油版</td>
            </tr>
            <tr>
              <td>18</td>
              <td>氢氧化钠</td>
              <td>-</td>
              <td>{{ detailRes.fstnaohsrlicerrq }}</td>
              <td>DF机带iCER燃气版</td>
            </tr>

          </tbody>
        </table>
        <table id="fst" cellpadding="0" cellspacing="0">
          <thead>
            <tr>
              <th colspan="7">后续机台架试车中燃料等消耗量</th>
            </tr>
            <tr class="title">
              <th>序号</th>
              <th>项目</th>
              <th>消耗量（kg）</th>
              <th>消耗量（L）</th>
              <th>备注</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>1</td>
              <td>燃油</td>
              <td>{{ detailRes.fnostranyoucgj }}</td>
              <td>{{ (detailRes.fstranyoucgj/0.835).toFixed(2) }}</td>
              <td>常规机</td>
            </tr>
            <tr>
              <td>2</td>
              <td>燃油</td>
              <td>{{ detailRes.fnostranyoucgjscr }}</td>
              <td>{{ (detailRes.fnostranyoucgjscr/0.835).toFixed(2) }}</td>
              <td>常规机带HPSCR/LPSCR/EGRBP/iSCR</td>
            </tr>
            <tr>
              <td>3</td>
              <td>燃油</td>
              <td>{{ detailRes.fnostranyoucgjegr }}</td>
              <td>{{ (detailRes.fnostranyoucgjegr/0.835).toFixed(2) }}</td>
              <td>常规机带EcoEGR</td>
            </tr>
            <tr>
              <td>4</td>
              <td>燃油</td>
              <td>{{ detailRes.fnostranyousyldf }}</td>
              <td>{{ (detailRes.fnostranyousyldf/0.835).toFixed(2) }}</td>
              <td>双燃料DF机,DF机ICER燃气版,DF带SCR用此乘以1.5</td>
            </tr>
            <tr>
              <td>5</td>
              <td>燃油</td>
              <td>{{ detailRes.fnostranyousylicer }}</td>
              <td>{{ (detailRes.fnostranyousylicer/0.835).toFixed(2) }}</td>
              <td>DF机带iCER燃油版</td>
            </tr>
            <!-- 燃气 -->
            <tr>
              <td>6</td>
              <td>燃气</td>
              <td>{{ detailRes.fnostranqisyldf }}</td>
              <td>{{ (detailRes.fnostranqisyldf/0.792).toFixed(2) }}</td>
              <td>双燃料DF机,DF带SCR</td>
            </tr>
            <tr>
              <td>7</td>
              <td>燃气</td>
              <td>{{ detailRes.fnostranqisylicer }}</td>
              <td>{{ (detailRes.fnostranqisylicer/0.792).toFixed(2) }}</td>
              <td>DF机带iCER燃油版或燃气版</td>
            </tr>
            <!-- 汽缸油 -->
            <tr>
              <td>8</td>
              <td>汽缸油</td>
              <td>{{ detailRes.fnostqigangyoucgj }}</td>
              <td>{{ (detailRes.fnostqigangyoucgj/0.945).toFixed(2) }}</td>
              <td>常规机</td>
            </tr>
            <tr>
              <td>9</td>
              <td>汽缸油</td>
              <td>{{ detailRes.fnostqigangyoucgjscr }}</td>
              <td>{{ (detailRes.fnostqigangyoucgjscr/0.945).toFixed(2) }}</td>
              <td>常规机带HPSCR/LPSCR/EGRBP/iSCR</td>
            </tr>
            <tr>
              <td>10</td>
              <td>汽缸油</td>
              <td>{{ detailRes.fnostqigangyoucgjegr }}</td>
              <td>{{ (detailRes.fnostqigangyoucgjegr/0.945).toFixed(2) }}</td>
              <td>常规机带EcoEGR</td>
            </tr>
            <tr>
              <td>11</td>
              <td>汽缸油</td>
              <td>{{ detailRes.fnostqigangyousyldf }}</td>
              <td>{{ (detailRes.fnostqigangyousyldf/0.945).toFixed(2) }}</td>
              <td>非首台双燃料DF机</td>
            </tr>
            <tr>
              <td>12</td>
              <td>汽缸油</td>
              <td>{{ detailRes.fnostqigangyousylicerry }}</td>
              <td>{{ (detailRes.fnostqigangyousylicerry/0.945).toFixed(2) }}</td>
              <td>DF机带iCER燃油版</td>
            </tr>
            <tr>
              <td>13</td>
              <td>汽缸油</td>
              <td>{{ detailRes.fnostqigangyousylicerrq }}</td>
              <td>{{ (detailRes.fnostqigangyousylicerrq/0.945).toFixed(2) }}</td>
              <td>DF机带iCER燃气版</td>
            </tr>
            <!-- 尿素 -->
            <tr>
              <td>14</td>
              <td>尿素</td>
              <td>-</td>
              <td>{{ detailRes.fnostniaosucgjscr }}</td>
              <td>常规机带HPSCR/LPSCR/iSCR</td>
            </tr>
            <!-- 氢氧化钠 -->
            <tr>
              <td>15</td>
              <td>氢氧化钠</td>
              <td>-</td>
              <td>{{ detailRes.fnostnaohcgjegrbp }}</td>
              <td>常规机带EGRBP</td>
            </tr>
            <tr>
              <td>16</td>
              <td>氢氧化钠</td>
              <td>-</td>
              <td>{{ detailRes.fnostnaohcgjecoegr }}</td>
              <td>常规机带EcoEGR</td>
            </tr>
            <tr>
              <td>17</td>
              <td>氢氧化钠</td>
              <td>-</td>
              <td>{{ detailRes.fnostnaohsrlicerry }}</td>
              <td>DF机带iCER燃油版</td>
            </tr>
            <tr>
              <td>18</td>
              <td>氢氧化钠</td>
              <td>-</td>
              <td>{{ detailRes.fnostnaohsrlicerrq }}</td>
              <td>DF机带iCER燃气版</td>
            </tr>

          </tbody>
        </table>
      </div>
    </el-dialog>

    <el-dialog v-el-drag-dialog :visible.sync="addUserModal" title="添加／编辑" width="30%">
      <hr style="height:1px;margin-top:-33px;border:none;border-top:1px solid #ddd;" >
      <el-form v-loading="loadingForm" ref="form" :rules="rules" :inline="true" :model="form" label-width="150px" class="form1">

        <el-row >
          <el-col v-for="item in dialogThead" :span="24" :key="item.fid ">

            <el-form-item :label="item.frepcap" :prop="item.frepfld" >
              <template v-if="item.frepmeg == 1">
                <template v-if=" 'funit' === item.frepfld" >
                  <el-select v-model="form[item.frepfld]" class="select_el" clearable filterable placeholder="请选择">
                    <el-option
                      v-for="item2 in fuzhujichu[item.frepfld]"
                      :key="item2.finterid"
                      :label="item2.fname"
                      :value="item2.fname"/>
                  </el-select>
                </template>

                <template v-else-if=" 'fbrand' === item.frepfld" >
                  <el-select v-model="form[item.frepfld]" class="select_el" clearable filterable placeholder="请选择">
                    <el-option
                      v-for="item2 in brandList"
                      :key="item2.finterid"
                      :label="item2.fname"
                      :value="item2.fname"/>
                  </el-select>
                </template>

              </template>
              <!-- 多文本-->
              <template v-else-if="item.frepmeg == 6" >
                <template >
                  <el-input :rows="3" v-model="form[item.frepfld]" type="textarea" />
                </template>
              </template>
              <!-- 日期框-->
              <template v-else-if="item.frepmeg == 4" >
                <template >
                  <el-date-picker v-model="form[item.frepfld]" style="width:100%" class="date_el" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" />
                </template>
              </template>
              <!-- 禁止编辑-->
              <template v-else-if="item.frepmeg == 5" >
                <template >
                  <el-input v-model="form[item.frepfld]" :disabled="editText"/>
                </template>
              </template>

              <!-- 输入框 -->
              <template v-else >
                <el-input v-model="form[item.frepfld]" />
              </template>
            </el-form-item>
          </el-col>
        </el-row>

        <div class="dialog-footer">
          <el-form-item >
            <el-button :loading="loadingForm" type="primary" @click="confirm" >确认</el-button>
            <el-button @click="addUserModal=false">取消</el-button>
          </el-form-item>
        </div>
      </el-form>
    </el-dialog>

    <!-- 参数配置 -->
    <el-dialog v-el-drag-dialog :visible.sync="configModal" :close-on-click-modal="false" class="config-dialog">
      <head-table
        :config-list="configList"
        :key-value="key"
        @updateConfigData="getUpdateConfigData" />
    </el-dialog>

    <!-- SQL弹窗 -->
    <el-dialog v-el-drag-dialog :visible.sync="dialogSQLModal" :append-to-body="true" title="执行结果">
      <el-form v-loading="loadingFormSQL" ref="formSQL" :rules="rulesSQL" :model="formSQL" label-width="120px">
        <el-form-item label="SQL语句" prop="gzsql">
          <el-input v-model="formSQL.gzsql" :autosize="{ minRows: 14 }" type="textarea" style="width:400px;"/>
        </el-form-item>
        <el-form-item>
          <el-button :loading="loadingFormSQL" type="primary" @click="confirmSQL" >确认</el-button>
          <el-button @click="dialogSQLModal=false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 下载模板 -->
    <el-dialog :visible.sync="tableSetExcel" title="提示：信息导出" style="width:30%; margin:auto;">
      <el-button type="primary" @click="downloadFile1()">导出</el-button>
    </el-dialog>

    <!-- 导入 -->
    <el-dialog
      v-el-drag-dialog
      :title="importGrid.title"
      :visible.sync="importGrid.fmodal"
      :close-on-click-modal="false"
      :show-close="true"
      class="import-set-modal"
      width="78%"
      @close="closeImportDialog">
      <div class="search-grid" style="margin-bottom: 20px;">
        <!-- <vxe-button status="success" icon="vxe-icon-add" content="新增" @click="importGridAdd"/> -->
        <vxe-button status="success" icon="vxe-icon-save" content="保存" @click="importGridSave"/>
        <vxe-button class="import-excel" status="primary" content="导入Excel" @click="toImport" />
        <vxe-button status="success" icon="vxe-icon-delete" content="删除" @click="importGridDel"/>
        <ExcelImport
          :ref="importGrid.excelRefs"
          :data-row="importGrid.dataRow"
          :value-match="importGrid.fieldArr"
          :accept="importGrid.accept"
          @changeExcel="uploadExamFile" />
      </div>
      <vxe-grid
        :class="importGrid.class"
        :id="importGrid.id"
        :ref="importGrid.gridRefs"
        :print-config="{}"
        :import-config="{}"
        :export-config="{}"
        :columns="importGrid.columns"
        :toolbar-config="importGrid.tableToolbar"
        :data="importGrid.data"
        :custom-config="{storage: true}"
        :edit-config="{trigger: 'click', mode: 'row', showStatus: true}"
        align="center"
        height="450"
        border
        resizable
        keep-source>
        <template #fbrand_edit="{row}">
          <vxe-input v-model="row.fbrand" />
        </template>
        <template #fmodel_edit="{row}">
          <vxe-input v-model="row.fmodel" />
        </template>
        <template #funit_edit="{row}">
          <vxe-input v-model="row.funit" />
        </template>
        <template #fpower_edit="{row}">
          <vxe-input v-model="row.fpower" />
        </template>
        <template #fmali_edit="{row}">
          <vxe-input v-model="row.fmali" />
        </template>
        <template #fzhuansu_edit="{row}">
          <vxe-input v-model="row.fzhuansu" />
        </template>
        <template #fchuanjishe_edit="{row}">
          <vxe-input v-model="row.fchuanjishe" />
        </template>
        <template #fzjjianyanf_edit="{row}">
          <vxe-input v-model="row.fzjjianyanf" />
        </template>
        <template #fnoxpaifangf_edit="{row}">
          <vxe-input v-model="row.fnoxpaifangf" />
        </template>
        <template #fzhusufRMB_edit="{row}">
          <vxe-input v-model="row.fzhusufRMB" />
        </template>
        <template #fguolufRMB_edit="{row}">
          <vxe-input v-model="row.fguolufRMB" />
        </template>
        <template #fzhengshuf_edit="{row}">
          <vxe-input v-model="row.fzhengshuf" />
        </template>
        <template #fpaifangtestfRMB_edit="{row}">
          <vxe-input v-model="row.fpaifangtestfRMB" />
        </template>
        <template #fzztaxAmount_edit="{row}">
          <vxe-input v-model="row.fzztaxAmount" />
        </template>
        <template #fallamount_edit="{row}">
          <vxe-input v-model="row.fallamount" />
        </template>
        <template #fcreatetime_edit="{row}">
          <vxe-input v-model="row.fcreatetime" />
        </template>
        <template #FStatus_edit="{row}">
          <vxe-input v-model="row.FStatus" />
        </template>
        <template #checkName_edit="{row}">
          <vxe-input v-model="row.checkName" />
        </template>
        <template #FExchangeRate_edit="{row}">
          <vxe-input v-model="row.FExchangeRate" />
        </template>
        <template #fzjjianyanfRMB_edit="{row}">
          <vxe-input v-model="row.fzjjianyanfRMB" />
        </template>
        <template #fnoxpaifangfRMB_edit="{row}">
          <vxe-input v-model="row.fnoxpaifangfRMB" />
        </template>
        <template #fjizuojijiafRMB_edit="{row}">
          <vxe-input v-model="row.fjizuojijiafRMB" />
        </template>
        <template #fzhengshufRMB_edit="{row}">
          <vxe-input v-model="row.fzhengshufRMB" />
        </template>
        <template #fhuosibutieRMB_edit="{row}">
          <vxe-input v-model="row.fhuosibutieRMB" />
        </template>
        <template #franyoufRMB_edit="{row}">
          <vxe-input v-model="row.franyoufRMB" />
        </template>
        <template #flvtuf_edit="{row}">
          <vxe-input v-model="row.flvtuf" />
        </template>
        <template #flvtufRMB_edit="{row}">
          <vxe-input v-model="row.flvtufRMB" />
        </template>
        <template #fchanjianfeiABS_edit="{row}">
          <vxe-input v-model="row.fchanjianfeiABS" />
        </template>
        <template #fremark_edit="{row}">
          <vxe-input v-model="row.fremark" />
        </template>
      </vxe-grid>
    </el-dialog>

  </div>
</template>
<script>
let FRepKey = ''
let opername = ''
const defaultFormThead = []

import HeadTable from '../salary/headTable/index.vue'
import { configColumn, checkStatus } from '../../api/salary'
import { brand } from '../../mixins/brand'
import { download } from '../../mixins/download.js'
import { common } from '../../mixins/common'
import { pagination } from '../../mixins/pagination'
import { parseTime } from '../../utils/index'
import { tableConfig, apiSql, apiFileSave, downFileUrl } from '../../api/account'
import { FImportGEN, genAdd, genDel, genList } from '../../api/gen'
import { XLSXOBJ } from '../../utils/XLSXExportExcel'
import '../../styles/common.scss'
import '../../styles/svg.scss'

export default {
  name: 'Index',
  components: {
    HeadTable
  },
  filters: {
    parseTime(time, type) {
      return parseTime(time, type)
    }
  },
  mixins: [download, common, pagination, brand],
  data() {
    return {
      importGrid: {
        class: 'import-set-modal',
        rows: '',
        fmodel: '',
        fbrand: '',
        title: '船检费ABS（导入）',
        excelRefs: 'importExcel', // ExcelImport
        dataRow: 0, // 数据开始行 默认从第0行开始
        fieldCap: [
          { field: 'fbrand', frecap: '品牌' },
          { field: 'fmodel', frecap: '主机型号' },
          { field: 'funit', frecap: '主计量单位' },
          { field: 'fpower', frecap: '功率' },
          { field: 'fmali', frecap: '马力' },
          { field: 'fzhuansu', frecap: '转速' },
          { field: 'fchuanjishe', frecap: '船级社' },
          { field: 'fzjjianyanf', frecap: '整机检验费' },
          { field: 'fnoxpaifangf', frecap: 'NOX排放费' },
          { field: 'fzhusufRMB', frecap: '住宿费用人民币' },
          { field: 'fguolufRMB', frecap: '过路费人民币' },
          { field: 'fzhengshuf', frecap: '证书费' },
          { field: 'fpaifangtestfRMB', frecap: '排放测试费用' },
          { field: 'fzztaxAmount', frecap: '增值税' },
          { field: 'fallamount', frecap: '合计金额' },
          { field: 'fcreatetime', frecap: '日期' },
          { field: 'FStatus', frecap: '审核' },
          { field: 'checkName', frecap: '审核人' },
          { field: 'FExchangeRate', frecap: '美元汇率' },
          { field: 'fzjjianyanfRMB', frecap: '整机检验费人民币' },
          { field: 'fnoxpaifangfRMB', frecap: 'NOX排放费人民币' },
          { field: 'fjizuojijiafRMB', frecap: '过程检验费用人民币' },
          { field: 'fzhengshufRMB', frecap: '证书费人民币' },
          { field: 'fhuosibutieRMB', frecap: '伙食补贴人民币' },
          { field: 'franyoufRMB', frecap: '燃油费用人民币' },
          { field: 'flvtuf', frecap: '旅途时间费用' },
          { field: 'flvtufRMB', frecap: '旅途时间费用人民币' },
          { field: 'fchanjianfeiABS', frecap: '船检费ABS' },
          { field: 'fremark', frecap: '备注' }
        ],
        fieldArr: [], // 数据列 必须与excel中的表列顺序相对应
        valueTitle: [], // frecap
        accept: '.xls,.xlsx',
        id: 'import-grid',
        gridRefs: 'importTable', // vxe-grid
        fmodal: false,
        data: [],
        columns: [
          { type: 'checkbox', width: 50 },
          { type: 'seq', width: 60 }
        ]
      },

      detailRes: {},
      jxModel: false,
      inputVal: 0,
      mergeFooterItems: [{ row: 0, col: 1, rowspan: 1, colspan: 6 }],
      hzTableData: [],
      hz2Merge: [{ row: 0, col: 1, rowspan: 1, colspan: 6 }],
      hz2TableData: [],

      value: '',
      options: [],
      FRepKey: '',
      keyword: '',
      fdeleted: '',
      fdeletedList: [

      ],
      fdeletedListDiaL: [

      ],
      gapTime: '',
      start_time: '',
      end_time: '',

      // 表头、表格设置
      tableData: [],
      tableList: [],
      defaultFormThead: [],
      formThead: defaultFormThead,
      dialogThead: [],
      curData: {},

      listLoading: false,
      list: [],
      configModal: false,
      configLoading: false,

      loadingForm: false,
      configList: [],
      key: 0,
      // SQL弹窗
      dialogSQLModal: false,
      loadingFormSQL: false,
      formSQL: {
        gzsql: ''
      },
      rulesSQL: {

      },

      form: {},
      rules: {

      },
      addUserModal: false,
      // loadingForm: false

      fileList: [],

      // 批量删除
      checkData: [],
      selectedData: [],

      // 用户菜单
      menusList: [],
      limits: [],
      fuzhujichu: {},
      userKey: '',
      fmofanName: '',

      bmwzList: [ // 部门位置
        {
          finterid: 0,
          fname: '钢壳'
        },
        {
          finterid: 1,
          fname: '铝壳'
        },
        {
          finterid: 2,
          fname: '14500'
        }
      ],

      fisranyouhz: 1,
      fisranyouhzList: [
        {
          value: 0,
          label: '全部'
        },
        {
          value: 1,
          label: '燃油'
        },
        {
          value: 2,
          label: '甲醇机'
        }
      ],

      upData: {},
      fdeptname: '', // 部门
      bmList: [], // 部门
      xlList: [], // 学历
      zwList: [], // 职务
      xbList: [], // 性别
      lzztList: [],
      fileListBasic: [],
      baseList: [],
      upDataBasic: {},

      opername: '',
      detail: '',
      detailVisible: false,
      editText: false,
      tableSetExcel: false,
      lookSetShow: false,
      oriColumnData: [],
      setConfigData: []

    }
  },
  async mounted() {
    await this.getColumns()

    this.userKey = this.$route.meta.FRepKey
    FRepKey = this.$route.meta.FRepKey
    this.upDataBasic.db = this.globalDb.db
    opername = decodeURIComponent(this.globalDb.fname)
    this.opername = decodeURIComponent(this.globalDb.fname)

    this.upDataBasic.FRepKey = this.$route.meta.FRepKey
    this.lookSetShow = JSON.parse(localStorage.getItem('flookSet'))

    this.upData.db = this.globalDb.db
    this.fmofanName = this.$route.meta.title

    await this.getAllData()
    // 获取单位
    // await this.getunit()

    // 菜单列表（权限）
    const menuRes = JSON.parse(localStorage.getItem('setMenuData'))
    this.menusList = menuRes
    if (menuRes.length >= 1) {
      menuRes.map(it => {
        it.children.map(item => {
          if (item.fobjectid === this.userKey) {
            this.$set(this, 'limits', item.child)
          }
        })
      })
    }

    // 获取辅助资料
    const fuzhujichu = JSON.parse(localStorage.getItem('fuzhujichuData'))
    this.$set(this, 'fuzhujichu', fuzhujichu)
    // 参数设置
    const setConfigData = JSON.parse(localStorage.getItem('setConfigData'))
    this.$set(this, 'setConfigData', setConfigData)
    // console.log(setConfigData.fsethuilv)
  },
  methods: {
    getColumns() {
      this.importGrid.fieldCap.map(item => {
        this.importGrid.fieldArr.push(item.field)
        this.importGrid.valueTitle.push(item.frecap)
        this.importGrid.columns.push({
          field: item.field,
          title: item.frecap,
          editRender: {},
          slots: { edit: item.field + '_edit' }
        })
      })
    },
    exportTableData() {
      this.importGrid.fmodal = true
      this.importGridDel()
    },
    // 获取数据
    uploadExamFile(data) {
      console.log('导出的数据', data)
      this.importGrid.data = data
    },
    importData() {
      this.importGrid.fmodal = true
      this.importGridDel()
    },
    toImport() {
      this.$refs[this.importGrid.excelRefs].open()
    },
    importGridAdd() { // 新增
      const $grid = this.$refs[this.importGrid.gridRefs]
      $grid.insertAt(-1, -1)
    },
    importGridDel() { // 删除当前行
      const $grid = this.$refs[this.importGrid.gridRefs]
      if ($grid) {
        const checkData = $grid.getCheckboxRecords()
        if (checkData.length) {
          $grid.removeCheckboxRow()
        } else {
          this.importGrid.data = []
          $grid.remove($grid.getCheckboxRecords())
        }
      }
    },
    async importGridSave() { // 保存
      const $grid = this.$refs[this.importGrid.gridRefs]
      $grid.getRecordset()
      const { fullData } = $grid.getTableData()
      // console.log(tableData, ' importGridSave tableData')
      try {
        const res = await FImportGEN({
          FRepKey,
          // fbillno: this.importGrid.fbillno,
          // rows: this.importGrid.rows,
          opername: this.opername,
          // fmodel: this.importGrid.fmodel,
          // fbrand: this.importGrid.fbrand,
          data: fullData
        })
        if (res.Error === 0) {
          this.$message({
            message: res.Message,
            type: 'success'
          })
          this.importGrid.rows = ''
          this.importGrid.fbillno = ''
          this.importGrid.fmodel = ''
          this.importGrid.fbrand = ''
          this.importGridDel()
          this.importGrid.fmodal = false
          await this.getAllData()
          // console.log(this.importGrid, ' this.importGrid')
        } else {
          this.$message({
            message: res.Message,
            type: 'error'
          })
        }
      } catch (error) {
        console.log(error)
      }
    },
    closeImportDialog() {
      this.importGrid.rows = ''
      this.importGrid.fbillno = ''
      this.importGrid.fmodel = ''
      this.importGrid.fbrand = ''
      this.importGridDel()
    },
    exportSCBJD() {
      XLSXOBJ.ExportExcelData(['st', 'fst'], '燃油汇总' + parseTime(new Date().getTime(), '{y}-{m}-{d}__{h}{i}'))
    },
    // 导入数据上面----------------
    tableClick(row, column, event) {
      console.log(row, ' row')
      this.detailRes = row
      this.jxModel = true
      this.hzTableData = [{
        'rownumber': '1',
        'fid': 21,
        'fmodel': '6X40-B',
        'fbillno': 'YC20221216000021',
        'fcreatetime': '2023-02-16 17:04:39',
        'fstranyoucgj': '102899.82',
        'fstranyoucgjscr': '196588.94',
        'fstranyoucgjegr': '295796.68',
        'fstranyousyldf': '164401.12',
        'fstranyousylicer': '175259.54',
        'fstranqisyldf': '61501.30',
        'fstranqisylicer': '123371.36',
        'fstqigangyoucgj': '520.87',
        'fstqigangyoucgjscr': '960.73',
        'fstqigangyoucgjegr': '1460.93',
        'fstqigangyousyldf': '885.11',
        'fstqigangyousylicerry': '1620.15',
        'fstqigangyousylicerrq': '1252.15',
        'fstniaosucgjscr': '15480.00',
        'fstnaohcgjegrbp': '2263.50',
        'fstnaohcgjecoegr': '4527.00',
        'fstnaohsrlicerry': '3755.50',
        'fstnaohsrlicerrq': '1899.00',
        'fnostranyoucgjscr': '182139.44',
        'fnostranyoucgjegr': '278632.78',
        'fnostranyousyldf': '158176.72',
        'fnostranyousylicer': '168684.14',
        'fnostranqisyldf': '57991.30',
        'fnostranqisylicer': '116351.36',
        'fnostqigangyoucgj': '508.39',
        'fnostqigangyoucgjscr': '895.21',
        'fnostqigangyoucgjegr': '1382.93',
        'fnostqigangyousyldf': '853.91',
        'fnostqigangyousylicerry': '1551.51',
        'fnostqigangyousylicerrq': '1202.23',
        'fnostniaosucgjscr': '13780.00',
        'fnostnaohcgjegrbp': '1966.00',
        'fnostnaohcgjecoegr': '3932.00',
        'fnostnaohsrlicerry': '3605.50',
        'fnostnaohsrlicerrq': '1794.00',
        'fpower': '3900',
        'fmoheqigangyouhz': '20.67',
        'fmoheranyouhz': '3692.08',
        'fry29003': '99207.74',
        'fqg29003': '500.20',
        'fnaoh29003': 0,
        'fnory29003': '96493.34',
        'fnoqg29003': '487.72',
        'fnonaoh29003': 0,
        'fry29004': '93689.12',
        'fqg29004': '439.86',
        'fns29004': '15480.00',
        'fnaoh29004': '2263.50',
        'fnory29004': '81954.02',
        'fnoqg29004': '386.82',
        'fnons29004': '13780.00',
        'fnonaoh29004': '1966.00',
        'fry29005': '72359.72',
        'fqg29005': '368.00',
        'fyry29005': 0,
        'fnaoh29005': '1856.50',
        'fnory29005': '68498.72',
        'fnoqg29005': '349.28',
        'fnoyry29005': 0,
        'fnonaoh29005': '1811.50',
        'fry29006': '61501.30',
        'fqg29006': '364.24',
        'fyry29006': 0,
        'fnaoh29006': '1839.00',
        'fnory29006': '57991.30',
        'fnoqg29006': '345.52',
        'fnoyry29006': 0,
        'fnonaoh29006': '1794.00',
        'fry29007': '61870.06',
        'fqg29007': '367.04',
        'fyry29007': 0,
        'fnaoh29007': '1899.00',
        'fnory29007': '58360.06',
        'fnoqg29007': '348.32',
        'fnoyry29007': 0,
        'fnonaoh29007': '1794.00',
        'fnostranyoucgj': '100185.42',
        'fstatus': 0,
        'checkname': ''
      }]
      this.hz2TableData = [{
        // 'rownumber': '1',
        // 'fid': 21,
        // 'fmodel': '6X40-B',
        // 'fbillno': 'YC20221216000021',
        // 'fcreatetime': '2023-02-16 17:04:39',
        // 常规机
        // 常规机带HPSCR/LPSCR/EGRBP
        // 常规机带EcoEGR
        // <td>双燃料DF机</td>

        // 'fstranyoucgj': '102899.82',
        // 'fstranyoucgjscr': '196588.94',
        // 'fstranyoucgjegr': '295796.68',
        // 'fstranyousyldf': '164401.12',
        // 'fstranyousylicer': '175259.54',
        // 'fstranqisyldf': '61501.30',
        // 'fstranqisylicer': '123371.36',

        // 'fstqigangyoucgj': '520.87',
        // 'fstqigangyoucgjscr': '960.73',
        // 'fstqigangyoucgjegr': '1460.93',
        // 'fstqigangyousyldf': '885.11',
        // 'fstqigangyousylicerry': '1620.15',
        // 'fstqigangyousylicerrq': '1252.15',

        // 'fstniaosucgjscr': '15480.00',
        // 'fstnaohcgjegrbp': '2263.50',
        // 'fstnaohcgjecoegr': '4527.00',
        // 'fstnaohsrlicerry': '3755.50',
        // 'fstnaohsrlicerrq': '1899.00',

        // 'fnostranyoucgjscr': '182139.44',
        // 'fnostranyoucgjegr': '278632.78',
        // 'fnostranyousyldf': '158176.72',
        // 'fnostranyousylicer': '168684.14',
        // 'fnostranqisyldf': '57991.30',
        // 'fnostranqisylicer': '116351.36',
        // 'fnostqigangyoucgj': '508.39',
        // 'fnostqigangyoucgjscr': '895.21',
        // 'fnostqigangyoucgjegr': '1382.93',
        // 'fnostqigangyousyldf': '853.91',
        // 'fnostqigangyousylicerry': '1551.51',
        // 'fnostqigangyousylicerrq': '1202.23',
        // 'fnostniaosucgjscr': '13780.00',
        // 'fnostnaohcgjegrbp': '1966.00',
        // 'fnostnaohcgjecoegr': '3932.00',
        'fnostnaohsrlicerry': '3605.50',
        'fnostnaohsrlicerrq': '1794.00',
        'fpower': '3900',
        'fmoheqigangyouhz': '20.67',
        'fmoheranyouhz': '3692.08',
        'fry29003': '99207.74',
        'fqg29003': '500.20',
        'fnaoh29003': 0,
        'fnory29003': '96493.34',
        'fnoqg29003': '487.72',
        'fnonaoh29003': 0,
        'fry29004': '93689.12',
        'fqg29004': '439.86',
        'fns29004': '15480.00',
        'fnaoh29004': '2263.50',
        'fnory29004': '81954.02',
        'fnoqg29004': '386.82',
        'fnons29004': '13780.00',
        'fnonaoh29004': '1966.00',
        'fry29005': '72359.72',
        'fqg29005': '368.00',
        'fyry29005': 0,
        'fnaoh29005': '1856.50',
        'fnory29005': '68498.72',
        'fnoqg29005': '349.28',
        'fnoyry29005': 0,
        'fnonaoh29005': '1811.50',
        'fry29006': '61501.30',
        'fqg29006': '364.24',
        'fyry29006': 0,
        'fnaoh29006': '1839.00',
        'fnory29006': '57991.30',
        'fnoqg29006': '345.52',
        'fnoyry29006': 0,
        'fnonaoh29006': '1794.00',
        'fry29007': '61870.06',
        'fqg29007': '367.04',
        'fyry29007': 0,
        'fnaoh29007': '1899.00',
        'fnory29007': '58360.06',
        'fnoqg29007': '348.32',
        'fnoyry29007': 0,
        'fnonaoh29007': '1794.00'
        // 'fnostranyoucgj': '100185.42'
        // 'fstatus': 0,
        // 'checkname': ''
      }]
    },
    // 表尾数据
    hzMethod({ columns, data }) {
      return []
    },
    hz2Method({ columns, data }) {
      return []
    },
    // 刷新
    refresh() {
      window.location.reload()
    },

    async toDetail(data) {
      this.detailVisible = true
      this.detail = data
    },

    selectFBirthday(val) {
      this.form.fbirthday = parseTime(val, '{y}-{m}-{d}')
    },
    selectFHireDate(val) {
      this.form.fhiredate = parseTime(val, '{y}-{m}-{d}')
    },
    selectFLeaveDate(val) {
      this.form.fleavedate = parseTime(val, '{y}-{m}-{d}')
    },
    // -----------------上传开始---------------------
    beforeAvatarUpload(file) {
      var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
      const extension = testmsg === 'xls' || testmsg === 'xlsx'
      const isLt2M = file.size / 1024 / 1024 < 1
      if (!extension) {
        this.$message({
          message: '上传文件只能是 xls/xlsx格式!',
          type: 'warning'
        })
      }
      if (!isLt2M) {
        this.$message({
          message: '上传文件大小不能超过 1MB!',
          type: 'warning'
        })
      }

      const fd = new FormData()
      fd.append('file', file)

      if (extension) {
        return true
      } else {
        this.$message.warning('只能上传excel文件格式xls/xlsx')
        return false
      }
    },

    async submitUpload() {
      this.$refs.upload.submit()
    },

    handleRemove(file, fileList) {

    },
    handlePreview(file) {

    },
    exceed() {
      // 重复选择文件,弹出错误弹窗
      this.$message('最多仅支持上传一个文件')
    },
    notice(e) {
      if (e.code === 200) {
        this.$message(e.message)
      } else {
        this.$message(e.message)
      }
    },
    // -----------------上传结束---------------------
    // 表头数据
    async getAllHeadData() {
      try {
        this.listLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey
        })
        this.listLoading = false
        this.formThead = res.Data
        this.oriColumnData = res.Data

        // this.tableList = []
        this.formThead.map(item => {
          this.tableList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        // this.tableData = this.tableList.slice()
        let tableTemp
        if (this.selectedData.length) {
          tableTemp = this.selectedData
        } else {
          tableTemp = this.tableList.slice()
        }

        // 获取显示表头键值对
        this.formThead.filter(item => {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        // const listData = this.tableList.slice()
        const listData = tableTemp.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.listLoading = false
      }
    },

    // 表体数据————erp职员列表
    async getAllBodyData() {
      try {
        this.listLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.keyword,

          fstatus: this.fstatus,
          limit: this.total,
          page: this.currentPage,
          FRepKey
        })
        this.listLoading = false

        this.tableList = res.Data
        this.total = res.total
      } catch (error) {
        this.listLoading = false
      }
    },
    // 导出数据
    async downData() {
      await this.getAllBodyData()
      await this.getAllHeadData()
      await this.exportData()
    },
    async getAllData() {
      await this.getBodyData()
      await this.getHeadData()
    },

    selectSettings(val) {
      if (val === 0) {
        this.settings()
      } else if (val === 1) {
        this.dialogSQL()
      }
    },
    settings() {
      this.configModal = true
      this.getTableConfig()
    },

    // 更新数据
    async getUpdateConfigData() {
      await this.getTableConfig()
      await this.getBodyData()
      await this.getHeadData()
    },

    // SQL修改/更新
    async dialogSQL() {
      this.dialogSQLModal = true
      try {
        const res = await apiSql({
          db: this.globalDb.db,
          opername,
          FRepKey
        })

        if (res.Error === 0) {
          this.formSQL.gzsql = res.Data
          this.formSQL.FRepKey = FRepKey
        }
        setTimeout(() => {
          this.$refs['formSQL'].clearValidate()
        })
      } catch (error) {
        // console.log(error)
      }
    },

    confirmSQL() {
      this.$refs['formSQL'].validate(async(valid) => {
        if (valid) {
          try {
            this.formSQL.db = this.globalDb.db
            this.formSQL.opername = opername
            const res = await apiFileSave(this.formSQL)
            if (res.Error === 0) {
              this.dialogSQLModal = false
              this.$message({
                message: res.Message,
                type: 'success'
              })
            } else {
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            // console.log(error)
          }
        } else {
          return false
        }
      })
    },

    // 设置表格字段--获取数据
    async getTableConfig() {
      try {
        this.configLoading = true
        const res = await tableConfig({
          db: this.globalDb.db,
          opername,
          key: FRepKey
        })

        this.configList = res.Data

        this.key = FRepKey
        this.configLoading = false
      } catch (error) {
        this.configLoading = false
      }
    },

    // 表头数据
    async getHeadData() {
      try {
        this.listLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey
        })
        this.listLoading = false
        this.formThead = res.Data
        this.oriColumnData = res.Data

        // this.tableList = []
        this.formThead.map(item => {
          this.tableList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.tableData = this.tableList.slice()

        // 获取显示表头键值对
        this.formThead.filter(item => {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.tableList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.listLoading = false
      }
    },

    // 表体数据————erp职员列表
    async getBodyData() {
      try {
        this.listLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.keyword,

          fstatus: this.fstatus,
          fisranyouhz: this.fisranyouhz,
          limit: this.pagesize,
          page: this.currentPage,
          FRepKey
        })
        this.listLoading = false

        this.tableList = res.Data
        this.total = res.total
      } catch (error) {
        this.listLoading = false
      }
    },

    async searchUser() {
      await this.getAllData()
    },
    async handleSizeChange(val) {
      this.currentPage = 1
      this.pagesize = val
      await this.getAllData()
    },
    async handleCurrentChange(val) {
      this.currentPage = val
      await this.getAllData()
    },
    salaryCurrentChange(val) {
      this.curData = val
    },

    // 下载
    async handleDownload() {
      const res = await downFileUrl({
        db: this.globalDb.db,
        opername,
        FRepKey
      })
      if (res.Error === 0) {
        this.tableSetExcel = true
        this.url = res.Data
      } else {
        this.$message({
          message: res.Message,
          type: 'error'
        })
      }
    },

    downloadFile1() {
      this.tableSetExcel = false
      window.open('/api/downloadFile?FRepKey=' + FRepKey)
    },

    // -----------------上传模板开始---------------------
    beforeAvatarUploadBasic(file) {
      var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
      const extension = testmsg === 'xls' || testmsg === 'xlsx'
      const isLt2M = file.size / 1024 / 1024 < 1
      if (!extension) {
        this.$message({
          message: '上传文件只能是 xls/xlsx格式!',
          type: 'warning'
        })
      }
      if (!isLt2M) {
        this.$message({
          message: '上传文件大小不能超过 1MB!',
          type: 'warning'
        })
      }

      const fd = new FormData()
      fd.append('file', file)

      if (extension) {
        return true
      } else {
        this.$message.warning('只能上传excel文件格式xls/xlsx')
        return false
      }
    },

    async submitUploadBasic() {
      this.$refs.uploadBasic.submit()
    },

    handleRemoveBasic(file, fileList) {

    },
    handlePreviewBasic(file) {

    },
    exceedBasic() {
      // 重复选择文件,弹出错误弹窗
      this.$message('最多仅支持上传一个文件')
    },

    noticeBasic(e) {
      if (e.Error === 0) {
        this.$message(e.Message)
        this.getAllData()
        this.$refs.uploadBasic.clearFiles()
      } else {
        this.$message(e.Message)
      }
    },

    // 添加
    async addUser() {
      this.$router.push('/jzgl/scgegryqfstAdd?key=' + this.$route.meta.FRepKey)
      return
    },

    // 修改
    async editUser() {
      const data = this.selectedData[0]
      console.log(data, 'data')
      // if (data && Number(data.fstatus) === 1) {
      //   this.$message({
      //     message: '已审核，不能修改！',
      //     type: 'error'
      //   })
      //   return
      // }
      this.editText = true
      this.form = {}
      if (this.selectedData.length !== 1) {
        this.$message({
          message: '请选中要编辑的一行',
          type: 'warning'
        })
        return
      }

      this.$router.push('/jzgl/scgegryqfstAdd?key=27008&fid=' + data.fid)
    },

    async confirm() {
      this.$refs['form'].validate(async(valid) => {
        if (valid) {
          this.loadingForm = true
          try {
            this.form.db = this.globalDb.db
            this.form.opername = opername
            this.form.FRepKey = FRepKey

            const res = await genAdd(this.form)
            if (res.Error === 0) {
              this.loadingForm = false
              this.addUserModal = false
              this.$message({
                message: res.Message,
                type: 'success'
              })

              await this.getAllData()
            } else {
              this.loadingForm = false

              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            this.loadingForm = false
          }
        } else {
          return false
        }
      })
    },

    async delUser() {
      const data = this.checkData
      if (data.length < 1) {
        this.$message({
          message: '请选中要删除的一行',
          type: 'warning'
        })
        return
      }
      const dataTemp = this.selectedData
      const isFstatus = dataTemp.filter(it => Number(it.fstatus) === 1)

      if (isFstatus.length) {
        this.$message({
          message: '已审核，不能删除！',
          type: 'error'
        })
        return
      }

      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'btn-custom-cancel',
        type: 'warning'
      }).then(async() => {
        const fid = data.join(',')
        const res = await genDel({
          db: this.globalDb.db,
          opername,
          data: this.selectedData,
          fid: fid,
          FRepKey

        })
        if (res.Error === 0) {
          this.$message({
            message: res.Message,
            type: 'success'
          })
          await this.getAllData()
          return
        }
        this.$message({
          message: res.Message,
          type: 'error'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },

    // 合计
    getSummaries({ columns, data }) {
      const sums = []
      const arr = []
      this.oriColumnData.forEach((item, itemIndex) => {
        if (item.frepfld && item.frepsum === 1) {
          arr.push(item.frepfld)
        }
      })
      columns.forEach((column, columnIndex) => {
        if (columnIndex === 0) {
          sums[columnIndex] = '合计'
        } else {
          if (arr.indexOf(column.property) >= 0) {
            sums[columnIndex] = this.sumNum(data, column.property).toFixed(2)
          } else {
            sums[columnIndex] = ''
          }
        }
      })
      // 返回一个二维数组的表尾合计
      return sums
    },

    sumNum(list, field) { // DONE
      let count = 0
      list.forEach(item => {
        count += Number(item[field]) * 100
      })
      return (count / 100)
    },

    // 1—审核，0—反审
    async check(Fstatus) {
      if (!this.checkData.length) {
        this.$message({
          message: '请选择表格行数据',
          type: 'error'
        })
        return
      }
      if (Number(Fstatus) === 1) {
        this.$confirm('是否审核, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          cancelButtonClass: 'btn-custom-cancel',
          type: 'warning'
        }).then(async() => {
          try {
            const res = await checkStatus({
              db: this.globalDb.db,
              opername: decodeURIComponent(this.globalDb.fname),
              loginname: decodeURIComponent(this.globalDb.fname),
              FRepKey,
              Fstatus, // 1—审核，0—反审
              data: this.selectedData,
              fid: this.checkData.join(',')

            })
            if (res.Error === 0) {
              this.$message({
                message: res.Message,
                type: 'success'
              })
              await this.getAllData()
            } else {
              this.loadingForm = false
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            console.log(error)
          }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
      } else {
        try {
          const res = await checkStatus({
            db: this.globalDb.db,
            opername: decodeURIComponent(this.globalDb.fname),
            loginname: decodeURIComponent(this.globalDb.fname),
            FRepKey,
            Fstatus, // 1—审核，0—反审
            data: this.selectedData,
            fid: this.checkData.join(','),
            appname: ''
          })
          if (res.Error === 0) {
            this.$message({
              message: res.Message,
              type: 'success'
            })
            await this.getAllData()
          } else {
            this.loadingForm = false
            this.$message({
              message: res.Message,
              type: 'error'
            })
          }
        } catch (error) {
          console.log(error)
        }
      }
    },

    handleSelectionChange(val) {
      this.checkData = []
      this.selectedData = val
      val.map(it => {
        this.checkData.push(it.fid)
      })
    }

  }
}

</script>
<style lang="scss" scoped>
.config-dialog ::v-deep .el-dialog {
  width: 90%;
}

.input {
  width: 10%;
  margin-top: 10px;
  margin-bottom: 30px;
}
/deep/ .vxe-table--render-default .vxe-body--column:not(.col--ellipsis), .vxe-table--render-default .vxe-footer--column:not(.col--ellipsis), .vxe-table--render-default .vxe-header--column:not(.col--ellipsis) {
  padding: 22px 0;
  font-size: 16px;
  height: 20px;
  line-height: 20px;
}
/deep/ .vxe-header--row .vxe-cell .vxe-cell--title {
  font-size: 16px;
}

  .detail {
    // margin: 100px auto;
    // width: 1024px;
    // overflow: hidden;
    box-sizing: border-box;
    position: relative;
    width: 100%;
    margin-bottom: 30px;
    // border: 1px solid red;
    margin-top: -30px;
    min-height: 470px;
    .btn_box {
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      top: -40px;
      overflow: hidden;
      margin-bottom: 4px;
    }
  }
  /* 滚动条宽度 */
  ::-webkit-scrollbar {
    width: 0px;
    background-color: transparent;
  }

  /* 滚动条颜色 */
  ::-webkit-scrollbar-thumb {
    background-color: #27314d;
  }
  #st, #fst {
    float: left;
    width: 48%;
    border-spacing: 0px;
    border-collapse: collapse;
    border-bottom: 1px solid gray;
    caption {
      font-weight: bold;
      font-size: 16px;
      line-height: 16px;
      text-align: left;
      margin-top: 10px;
    }
    th,  td {
      height: 20px;
      text-align: center;
      border: 1px solid gray;
    }
    thead {
      .title {
        color: white;
        background-color: #38F;
        th:first-of-type {
          width: 40px;
        }
        th:last-of-type {
          width: 300px;
        }
      }
    }
    tbody {
      display: block;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      tr:nth-of-type(odd) {
        background: #EEE;
      }
      tr:nth-of-type(even) {
        background: #FFF;
      }
      tr {
        td {
          border-bottom: none;
        }
        td:first-of-type {
          width: 40px;
        }
        td:last-of-type {
          width: 300px;
        }
      }
    }
    tfoot {
      background-color: #71ea71;
    }
    thead tr,  tbody tr,  tfoot tr {
      box-sizing: border-box;
      table-layout: fixed;
      display: table;
      width: 100%;
    }
  }
  #fst {
    margin-left: 6px;
  }

.import-set-modal ::v-deep .el-dialog__body {
  padding: 0 20px;
}
</style>
